//
//  AccountTool.m
//  BeautyPicture
//
//  Created by 沈振邦 on 15/11/11.
//  Copyright © 2015年 szb. All rights reserved.
//
#define HMAccountFilepath [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject] stringByAppendingPathComponent:@"account.data"]

#import "AccountTool.h"


@implementation AccountTool

+ (void)save:(BPAccount *)account
{
    // 归档
    [NSKeyedArchiver archiveRootObject:account toFile:HMAccountFilepath];
}

+ (BPAccount *)account
{
    // 读取帐号
    BPAccount *account = [NSKeyedUnarchiver unarchiveObjectWithFile:HMAccountFilepath];
    
    return account;
}

//获取账号是否注册成功的信息
+ (void)postAccountWithParam:(BPRegisterAccountParam *)param success:(void (^)(BPAccount *result))success failure:(void (^)(NSError *error))failure
{
    [self postWithUrl:[NSString stringWithFormat:@"%@user/register",BPhttp] param:param resultClass:[BPAccount class] success:success failure:failure];
}

//获取短信验证码
+ (void)receiveMessageCode:(NSString *)phoneNumber success:(void (^)(BPRegisterAccountParam *result))success failure:(void (^)(NSError *error))failure
{
    [self getWithUrl:[NSString stringWithFormat:@"%@user/verify/mobile/%@",BPhttp,phoneNumber] param:nil resultClass:[BPRegisterAccountParam class] success:success failure:failure];
}

+ (void)addOrChangeOrdeleteAddress:(BPAddressModel *)param success:(void (^)(paramAddress *))success failure:(void (^)(NSError *))failure
{
    [self postWithUrl:[NSString stringWithFormat:@"%@user/updateAddress",BPhttp] param:param resultClass:[paramAddress class] success:success failure:failure];
}


@end
